package com.atguiguNIO.channel;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class SocketChannelDemo01 {


    public static void main(String[] args) {




        try {

            SocketChannel socketChannel = SocketChannel.open();
            socketChannel.connect(new InetSocketAddress("www.baidu.com", 80));

            ByteBuffer buffer = ByteBuffer.allocate(1024);

            getInfo(socketChannel);

            socketChannel.read(buffer);

            socketChannel.close();
            System.out.println("finish.......");
            getInfo(socketChannel);

        }catch (Exception e){
            e.printStackTrace();
        }

    }



    public static void getInfo(SocketChannel socketChannel) throws IOException {
        System.out.println("socketChannel.isConnected() = " + socketChannel.isConnected());
        System.out.println("socketChannel.isOpen() = " + socketChannel.isOpen());
        System.out.println("socketChannel.finishConnect() = " + socketChannel.finishConnect());
    }





}
